<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:15px;">
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red;">*</span>媒体名称</label>
            <div class="layui-input-block">
                <input type="text" name="mp_name" value="{$mp.mp_name}" required lay-verify="required" placeholder="请输入媒体名称" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">小程序的名称</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red;">*</span>公司名称</label>
            <div class="layui-input-block">
                <input type="text" name="com_name"  value="{$mp.com_name}" required lay-verify="required" placeholder="请输入公司名称" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">小程序的所属</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <select name="type" lay-filter="type" disabled>
                    <option value="1" {if $type == 1}selected{/if}>订阅号appid</option>
                    <option value="2" {if $type == 2}selected{/if}>服务号appid</option>
                    <option value="3" {if $type == 3}selected{/if}>APP</option>
                </select>
                <input type="hidden" name="current" value="{$type}">
            </div>
        </div>
        <div class="layui-form-item dy">
            <div class="layui-inline">
                <label class="layui-form-label">订阅号appid</label>
                <div class="layui-input-block">
                    <input type="text" name="dy_appid" value="{$mp.dy_appid}" placeholder="请输入订阅号appid" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">订阅号秘钥</label>
                <div class="layui-input-block">
                    <input type="text" name="dy_secret" value="{$mp.dy_secret}" placeholder="请输入订阅号秘钥" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item fw">
            <div class="layui-inline">
                <label class="layui-form-label">服务号appid</label>
                <div class="layui-input-block">
                    <input type="text" name="fw_appid" value="{$mp.fw_appid}" placeholder="请输入服务号appid" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">服务号秘钥</label>
                <div class="layui-input-block">
                    <input type="text" name="fw_secret" value="{$mp.fw_secret}" placeholder="请输入服务号秘钥" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item app">
            <div class="layui-inline">
                <label class="layui-form-label">APP秘钥</label>
                <div class="layui-input-block">
                    <input type="text" name="app_secret" value="{$mp.app_secret}" placeholder="请输入APP秘钥" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$mp.id}"/>
                <input class="layui-btn" lay-submit lay-filter="form" value="立即提交" readonly>
            </div>
        </div>
    </form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
    layui.use(['element', 'table','jquery','form','layer'], function(){
        let $ = layui.jquery
                ,element = layui.element
                ,layer = layui.layer
                ,form = layui.form;
        var type = $('input[name = current]').val();
        if(type == 1){
            $(".dy").show();
            $(".fw").hide();
            $(".app").hide();
        }else if(type == 2){
            $(".dy").hide();
            $(".fw").show();
            $(".app").hide();
        }else if(type == 3){
            $(".dy").hide();
            $(".fw").hide();
            $(".app").show();
        }

        //监听提交
        form.on('submit(form)', function (data) {
            let field = data.field;
            let isLoad;
            $.ajax({
                url: '{:url("Mp/edit")}',
                method: "post",
                data: field,
                beforeSend: function () {
                    isLoad = layer.load(0, {
                        shade: false
                    }); //0代表加载的风格，支持0-2
                },
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 1) {
                        setTimeout(function () {
                            let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.location.reload();
                        }, 2000);
                    }
                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });
            return false;
        });
    });

</script>